package pro.ticktock.base.tree.impl;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author lambert
 * @created 18-9-30
 */
public interface TypedTreeNode<T extends TypedTreeNode<T, NV>, NV> {

  public T getParent();

  public void setParent(T parent);

  default public T getRoot() {
    T node = (T)this;
    while (true) {
      T parent = node.getParent();
      if (parent == null) {
        break;
      } else {
        node = parent;
      }
    }
    return node;
  }

  public void setValue(NV value);

  public NV getValue();

  public Collection<T> getChildList();

  default public Collection<T> getUnmodifiableChildList() {
    return new ArrayList<>(getChildList());
  }

  public void addChild(T child);

  public void addChild(int idx, T child);

  public boolean removeChild(T child);

  public T removeChildAt(int idx);

  public int getChildCount();

  public T childAt(int index);

  public int indexOf(T child);

  public void clearChild();
}
